#include "TriangleBumper.h"


TriangleBumper::TriangleBumper(void)
{
	_p1 = vector3( 100, 10, 0 );
	_p2 = vector3( 150, 50, 0 );
	_p3 = vector3( 200, 10, 0 );
	_color = GREEN;
}


TriangleBumper::TriangleBumper(vector3 p1, vector3 p2, vector3 p3 )
{
	_p1 = p1;
	_p2 = p2;
	_p3 = p3;
	_color = GREEN;
}

TriangleBumper::~TriangleBumper(void){}

bool TriangleBumper::isBallCollidingWith( Ball * ball )
{
	vector3 * test_points = new vector3[ 6 ];
	test_points[0] = _p1; 
	test_points[1] = _p2;
	test_points[2] = _p3;
	test_points[3] = vector3( (_p1.getX() - _p2.getX())/2 + _p2.getX() , (_p1.getY() - _p2.getY())/2+_p2.getY(), 0 );
	test_points[4] = vector3( (_p2.getX() - _p3.getX())/2 + _p3.getX() , (_p2.getY() - _p3.getY())/2+_p3.getY(), 0 );
	test_points[5] = vector3( (_p3.getX() - _p1.getX())/2 + _p1.getX() , (_p3.getY() - _p1.getY())/2+_p3.getY(), 0 );
	
	for( int i = 0; i < 6;i++){
		if( ball->transform.position.distanceFrom( test_points[i] ) < ball->radius ){
			_color = BLUE;
			return true;
		}
	}
	_color = GREEN;
	return false;

}

void TriangleBumper::Render()
{
	vector3 * test_points = new vector3[ 3 ];
	test_points[0] = _p1; 
	test_points[1] = _p2;
	test_points[2] = _p3;
	DrawTools::drawPolyGon( test_points, 3, _color );
}